﻿

Public Class Clientes
    Dim globalimg As String
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub ClientesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ClientesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub Clientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.nominastipo' table. You can move, or remove it, as needed.
        Me.NominastipoTableAdapter.Fill(Me.DbFireAndIceDataSet.nominastipo)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empresas' table. You can move, or remove it, as needed.
        Me.EmpresasTableAdapter.Fill(Me.DbFireAndIceDataSet.empresas)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.clientes' table. You can move, or remove it, as needed.
        Me.ClientesTableAdapter.Fill(Me.DbFireAndIceDataSet.clientes)

    End Sub

    Private Sub PanelArriba_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PanelArriba.Paint

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                ClientesTableAdapter.DeleteQuery(IdclienteTextEdit.Text)
                Me.ClientesTableAdapter.Fill(Me.DbFireAndIceDataSet.clientes)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click

        If (NombreTextBox.Text.Length = 0) Then
            ErrorProvider1.SetError(NombreTextBox, "Debe ingresar un nombre")


        End If

        If (ApellidoTextBox.Text.Length = 0) Then
            ErrorProvider1.SetError(ApellidoTextBox, "Debe ingresar un Apellido")

        End If

        If (IdempresaGridLookUpEdit.Text.Length = 0) Then
            ErrorProvider1.SetError(IdempresaGridLookUpEdit, "Debe seleccionar una empresa")
        End If

        If ((NombreTextBox.Text.Length = 0) And (ApellidoTextBox.Text.Length = 0) And (IdempresaGridLookUpEdit.Text.Length = 0)) Then
            ErrorProvider1.SetError(NombreTextBox, "Debe ingresar un nombre")
            ErrorProvider1.SetError(ApellidoTextBox, "Debe ingresar un Apellido")
            ErrorProvider1.SetError(IdempresaGridLookUpEdit, "Debe seleccionar una empresa")

        Else
            ErrorProvider1.SetError(NombreTextBox, Nothing)
            ErrorProvider1.SetError(ApellidoTextBox, Nothing)
            ErrorProvider1.SetError(IdempresaGridLookUpEdit, Nothing)
            ClientesBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()

        End If



    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(NombreTextBox, Nothing)
        ErrorProvider1.SetError(ApellidoTextBox, Nothing)
        ErrorProvider1.SetError(IdempresaGridLookUpEdit, Nothing)
        Mostrar()
        Me.ClientesTableAdapter.Fill(Me.DbFireAndIceDataSet.clientes)
    End Sub

    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim openFile2 As New System.Windows.Forms.OpenFileDialog()
        Dim img As Byte

        openFile2.DefaultExt = "Picture"
        openFile2.Filter = "jpg (*.jpg)|*.jpg|png (*.png*)|*.png*"

        openFile2.ShowDialog()
        If openFile2.FileNames.Length > 0 Then
            Dim filename As String
            For Each filename In openFile2.FileNames
                FotografiaPictureBox.Image = System.Drawing.Image.FromFile(openFile2.FileName)
                FotografiaPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
                MsgBox(openFile2.FileName)
            Next
        End If
    End Sub

    'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    '    Dim var1 As Byte

    '    ClientesTableAdapter.InsertQuery(IdclienteTextEdit.Text, NombreTextBox.Text, ApellidoTextBox.Text, IdempresaGridLookUpEdit.EditValue, CodigoTextBox.Text, var1, IdnominaComboBox.Text)
    'End Sub

   
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class